package com.wn.ticket.web;

import com.wn.ticket.common.ResponseEntity;
import com.wn.ticket.entity.User;
import com.wn.ticket.service.UserArtistService;
import com.wn.ticket.service.UserPerformService;
import com.wn.ticket.vo.FocusVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 关注，收藏
 * @author 杜昭进
 * date: 2022/9/5
 */
@Slf4j
@RestController
@RequestMapping("/front/focus")
public class FocusOnController {

    @Autowired
    private UserArtistService userArtistService;

    @Autowired
    private UserPerformService userPerformService;

    /**
     * 关注增加
     * @param focusVo
     */
    @RequestMapping("/focusadd")
    public ResponseEntity focusadd(@RequestBody FocusVo focusVo){
        log.debug("roleVo:{}",focusVo);
        userArtistService.add(focusVo.getUser().getId(),focusVo.getArtistId());
        return ResponseEntity.success;
    }

    /**
     * 关注删除
     * @param focusVo
     */
    @RequestMapping("/focusdel")
    public ResponseEntity focusdel(@RequestBody FocusVo focusVo){
        log.debug("roleVo:{}",focusVo);
        userArtistService.deleted(focusVo.getUser().getId(),focusVo.getArtistId());
        return ResponseEntity.success;
    }

    /**
     * 关注查询
     * @param focusVo
     */
    @RequestMapping("/focuslist")
    public ResponseEntity focuslist(@RequestBody FocusVo focusVo){
        log.debug("roleVo:{}",focusVo);
        List<User> users = userArtistService.getNamesByUserId(focusVo.getUser().getId());
        return new ResponseEntity(users);
    }


    /**
     * 收藏增加
     * @param focusVo
     */
    @RequestMapping("/collectionadd")
    public ResponseEntity collectionadd(@RequestBody FocusVo focusVo){
        log.debug("roleVo:{}",focusVo);
        userPerformService.add(focusVo.getUser().getId(),focusVo.getPerformId());
        return ResponseEntity.success;
    }

    /**
     * 收藏删除
     * @param focusVo
     */
    @RequestMapping("/collectiondel")
    public ResponseEntity collectiondel(@RequestBody FocusVo focusVo){
        log.debug("roleVo:{}",focusVo);
        userPerformService.deleted(focusVo.getUser().getId(),focusVo.getPerformId());
        return ResponseEntity.success;
    }

    /**
     * 收藏查询
     * @param focusVo
     */
    @RequestMapping("/collectionlist")
    public ResponseEntity collectionlist(@RequestBody FocusVo focusVo){
        log.debug("roleVo:{}",focusVo);
        User users = userPerformService.getAllByUserId(focusVo.getUser().getId());
        return new ResponseEntity(users);
    }

}
